package com.ebs.md.fxmonitor.marketmonitor.model;

/**
 * Perforce Revision:
 *  $File: //depot/MarketData/fxmonitor/main/src/main/java/com/ebs/md/fxmonitor/marketmonitor/model/AbsOBRateAv.java $
 *  $Revision: #2 $  $Change: 116029 $  $DateTime: 2012/10/21 11:39:18 $  $Author: Arik.Sher $
 */

import java.io.Serializable;

import com.ebs.md.api.BookSide;
import com.ebs.md.api.Rate;
import com.ebs.md.api.product.PairProduct;


/**
 * Abstract OrderBook Rate Availability.
 * 
 * 
 */
public abstract class AbsOBRateAv
implements Serializable
{
	// gened with Eclipse
	private static final long serialVersionUID = -9125406051100024105L;

	protected long        timestamp; // id 1#4, milliseconds since 1970
	protected PairProduct pair;      // id 2#4
	protected BookSide    bookSide;  // id 3#4
	protected Rate        rate;      // id 4#4
	protected boolean     available;

	public AbsOBRateAv(AbsOBChange obChange, boolean available) {
		this.timestamp = obChange.getTimestamp();
		this.pair      = obChange.getPair();
		this.bookSide  = obChange.getBookSide();
		this.rate      = obChange.getRate();
		this.available = available;
	}

	public AbsOBRateAv(long timestamp, PairProduct pair, BookSide bookSide,	Rate rate, boolean available) {
		super();
		this.timestamp = timestamp;
		this.pair = pair;
		this.bookSide = bookSide;
		this.rate = rate;
		this.available = available;
	}

	// gened with Eclipse on timestamp, pair, bookSide and Rate
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((bookSide == null) ? 0 : bookSide.hashCode());
		result = prime * result + ((pair == null) ? 0 : pair.hashCode());
		result = prime * result + ((rate == null) ? 0 : rate.hashCode());
		result = prime * result + (int) (timestamp ^ (timestamp >>> 32));
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		AbsOBRateAv other = (AbsOBRateAv) obj;
		if (bookSide == null) {
			if (other.bookSide != null)
				return false;
		} else if (!bookSide.equals(other.bookSide))
			return false;
		if (pair == null) {
			if (other.pair != null)
				return false;
		} else if (!pair.equals(other.pair))
			return false;
		if (rate == null) {
			if (other.rate != null)
				return false;
		} else if (!rate.equals(other.rate))
			return false;
		if (timestamp != other.timestamp)
			return false;
		return true;
	}

	public long getTimestamp() {
		return timestamp;
	}
	public PairProduct getPair() {
		return pair;
	}
	public BookSide getBookSide() {
		return bookSide;
	}
	public Rate getRate() {
		return rate;
	}
	public boolean isAvailable() {
		return available;
	}

	protected final String shortClassName = getClass().getSimpleName();
	
	@Override
	public String toString() {
		return shortClassName
				+ "[bookSide=" + bookSide 
				+ ", pair=" + pair
				+ ", rate=" + rate 
				+ ", timestamp=" + timestamp
				+ ", available=" + available
				+ "]";
	}
	
}
